package huoye.shops.huoye.home.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.codeideology.android.utils.AXIImageLoader;
import com.codeideology.android.widget.convenientbanner.holder.ViewHolder;

import huoye.shops.R;
import huoye.shops.huoye.home.model.Banner;

public class BannerAdapter implements ViewHolder<Banner> {

    ImageView iv;
    TextView tv;
    View view;

    @Override
    public View createView(Context context) {
        view = View.inflate(context, R.layout.item_banner, null);
        iv = (ImageView) view.findViewById(R.id.item_banner_iv);
        tv = (TextView) view.findViewById(R.id.item_banner_tv);

        return view;
    }

    @Override
    public void bindView(Context context, int position, final Banner data) {
        tv.setText(data.getTitle());
        AXIImageLoader.displayImage((Activity) context, data.getImgUrl(), iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onBannerClick(data);
            }
        });
    }


    private OnBannerListener listener;
    public void setOnBannerListener(OnBannerListener onBannerListener) {
        this.listener = onBannerListener;
    }



    public interface OnBannerListener {
        void onBannerClick(Banner data);

    }
}